//
//  UILabel+Size.m
//  WC
//
//  Created by 杨鑫 on 15/5/4.
//  Copyright (c) 2015年 智康. All rights reserved.
//

#import "UILabel+Utilities.h"

@implementation UILabel (Utilities)

- (void)resize
{
    CGRect rect = [self.attributedText boundingRectWithSize:CGSizeMake(self.frame.size.width, CGFLOAT_MAX)
                                                    options:NSStringDrawingUsesLineFragmentOrigin
                                                    context:nil];
    
    CGRect frame = self.frame;
    frame.size.height = rect.size.height;
    
    self.frame = frame;
}

- (void)showAttributedText:(CGFloat)headIndent lineSpace:(CGFloat)lineSpace
{
    NSMutableParagraphStyle *pStyle = [[NSMutableParagraphStyle alloc] init];
    pStyle.alignment = self.textAlignment;
    pStyle.lineBreakMode = self.lineBreakMode;
    pStyle.firstLineHeadIndent = headIndent;
    pStyle.lineSpacing = lineSpace;
    
    NSString *text = self.text;
    if (!text) {
        text = @"";
    }
    self.text = nil;
    self.attributedText = [[NSAttributedString alloc] initWithString:text
                                                          attributes:@{NSParagraphStyleAttributeName: pStyle,
                                                                       NSForegroundColorAttributeName: self.textColor,
                                                                       NSFontAttributeName: self.font}];
}

@end
